package com.tanhua.dubbo.api;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.model.domain.User;
import com.tanhua.dubbo.mappers.UserMapper;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@DubboService
public class UserApiImpl  implements UserApi{

    @Autowired
    private UserMapper userMapper;

    //根据手机号码查询用户
    @Override
    public User findByMobile(String mobile) {
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("mobile",mobile);
        return userMapper.selectOne(qw);

    }
    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public void update(User user) {
            userMapper.updateById(user);
    }

    @Override
    public User findById(Long userId) {
        return userMapper.selectById(userId);
    }

    @Override
    public void updateById(String phone) {

    }

    @Override
    public void updateHx(User user) {
        userMapper.updateById(user);
    }

    @Override
    public User findByIds(Long userId) {
        return userMapper.selectById(userId);
    }

    /**
     * 根据环信id查看用户详情
     * @param huanxinId
     * @return
     */
    @Override
    public User findByHuanXin(String huanxinId) {
        QueryWrapper<User> qw = new QueryWrapper<>();
        qw.eq("hx_user",huanxinId);
        return userMapper.selectOne(qw);
    }

    @Override
    public List<User> getList() {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        return userMapper.selectList(wrapper);
    }
}
